﻿@inject Microsoft.CST.AttackSurfaceAnalyzer.Cli.AppData appData
@using Microsoft.CST.AttackSurfaceAnalyzer.Cli

<div>
    <div class="form-group">
        <div class="form-check">
            <input type="checkbox" class="form-check-input" id="enableFileSystemMonitorCheckbox" @bind="appData.MonitorOptions.EnableFileSystemMonitor" />
            <label class="form-check-label" for="enableFileSystemMonitorCheckbox">Enable FileSystem Monitor</label>
        </div>
    </div>
    <div class="form-group">
        <div class="form-check">
            <input type="checkbox" class="form-check-input" id="enableGatherHashesMonitorCheckbox" @bind="appData.MonitorOptions.GatherHashes" />
            <label class="form-check-label" for="enableGatherHashesMonitorCheckbox">Gather File Hashes</label>
        </div>
    </div>
    <div class="form-group">
        <label for="selectedDirectoriesString">Add Directory to Monitor:</label>
        <div class="form-row">
            <div class="col-9 mb-1">
                <input type="text" class="form-control" id="selectedDirectoriesString" placeholder="/my/path/" @bind="SelectedDirectoryInput" />
            </div>
            <div class="col">
                <button class="btn btn-secondary" @onclick="PushInputToList">Add</button>
            </div>
        </div>
    </div>
    <div class="form-group">
        <label for="selectedDirectoriesList">Selected Directories:</label>
        <div class="form-row">
            <div class="col-9 mb-1">
                <select class="form-control @directorySelectElementGlowClass.ClassName" id="selectedDirectoriesList" @bind="SelectedDirectoryTop">
                    @for (var i = 0; i < appData.MonitorOptions.MonitoredDirectories.Count(); i++)
                    {
                        <option value="@i">@appData.MonitorOptions.MonitoredDirectories.ToList()[i]</option>
                    }
                </select>
            </div>
            <div class="col">
                <button class="btn btn-secondary" @onclick="RemoveInputFromList">Remove</button>
            </div>
        </div>
    </div>
</div>

@code{
    Helper.GlowClass directorySelectElementGlowClass = new Helper.GlowClass();

    string SelectedDirectoryInput = string.Empty;
    int SelectedDirectoryTop;

    void RemoveInputFromList()
    {
        appData.MonitorOptions.MonitoredDirectories = appData.MonitorOptions.MonitoredDirectories.Except(appData.MonitorOptions.MonitoredDirectories.Skip(SelectedDirectoryTop-1).Take(1));
        Helper.ToggleGlow(() => InvokeAsync(StateHasChanged), directorySelectElementGlowClass, false);
    }

    void PushInputToList()
    {
        appData.MonitorOptions.MonitoredDirectories = appData.MonitorOptions.MonitoredDirectories.Union(new string[] { SelectedDirectoryInput });
        SelectedDirectoryTop = appData.MonitorOptions.MonitoredDirectories.Count() - 1;
        Helper.ToggleGlow(() => InvokeAsync(StateHasChanged), directorySelectElementGlowClass, true);
        SelectedDirectoryInput = string.Empty;
    }
}
